package com.example.application1.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.application1.Entity.ListDTO;
import com.example.application1.R;

import java.util.List;

public class expressAdapter extends RecyclerView.Adapter<expressAdapter.expressHolder> {

    private Context context;
//    private List<NewslistDTOX> expressList;
    private List<ListDTO> expressList;
    public expressAdapter(Context context, List<ListDTO> expressList) {
        this.context=context;
        this.expressList=expressList;
    }

    @NonNull
    @Override
    public expressHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return  new expressHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.express_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull expressHolder holder, int position) {
         holder.express_date.setText(expressList.get(position).getTime());
         holder.express_information.setText(expressList.get(position).getContent());
    }


    @Override
    public int getItemCount() {
        return expressList==null?0:expressList.size();
    }

    public  void refresh(List<ListDTO> expressList){
//      对适配器刷新
        this.expressList=expressList;
        notifyDataSetChanged();
        Log.d("lcj","notifyDataSetChanged");
    }


    public class expressHolder extends RecyclerView.ViewHolder{

        private TextView express_date;
        private TextView express_information;
        public expressHolder(@NonNull View itemView) {
            super(itemView);
           express_date=itemView.findViewById(R.id.express_date);
           express_information=itemView.findViewById(R.id.express_information);
        }
    }
}
